package MelbourneMap;

import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.util.ArrayList;

/**
 * Road class that extends the functionality of
 * the {@link Region} class by taking an extra
 * parameter in the constructor for the no of lanes 
 * and altering how the shape is built so that road
 * objects are drawn correctly.
 * 
 * @author David Zappia, 7183216
 *
 */
public class Road extends Region
{
	private int lanes;
	
	/**
	 * Class constructor specifying the name, data points to be used,
	 * the number of lanes and the region type.
	 * 
	 * @param n			the name of the region
	 * @param fileData	the list of data points for the region
	 * @param noLanes	the number of lanes for the region
	 * @param rgType	the type of the region
	 */
	public Road(String n, ArrayList<Node> fileData, int noLanes, int rgType) 
	{
		super(n, fileData, rgType);
		lanes = noLanes;
		shape = buildShape();
	}
	
	/**
	 * Creates a shape representing the region using the point 
	 * data provided. The Shape created is designed to be
	 * used when drawing a region.
	 * 
	 * @return	the Shape object for the region
	 */ 
	private Shape buildShape()
	{
		//boolean first = true;
		GeneralPath shape = new GeneralPath(); //new temp polygon shape
		
		for (int i = 0; i < shapeData.size(); i+=2)
		{
			shape.moveTo(shapeData.get(i).getX(), shapeData.get(i).getY());
			shape.lineTo(shapeData.get(i+1).getX(), shapeData.get(i+1).getY());
		}
		
		return shape;
	}
	
	/**
	 * Rebuilds the Shape object. To be used when then
	 * point data for the region has been altered and a 
	 * new shape needs to be created.
	 */
	public void rebuildShape()
	{
		shape = buildShape();
	}
	
	/**
	 * Gets the number of lanes for the region. To be used when
	 * saving the region data to file.
	 * 
	 * @return		the integer value representing the region type
	 */
	public int getLanes()
	{
		return lanes;
	}

}
